#!/usr/bin/python
# -*- coding: utf-8 -*-
#coding=utf-8
import datetimeDemo as tsLog
def demo():
    tsLog.logTs("setDemo", preNewLineNum=2)

    # 从内容上看，同一集合中，只能存储不可变的数据类型，包括整形、浮点型、字符串、元组，无法存储列表、字典、集合这些可变的数据类型
    # 集合对于每种数据元素，只会保留一份
    # 集合是无序的，所以每次输出时元素的排序顺序可能都不相同

    monthDic = {
        "January": 31,
        "February": 28,
        "March": 31,
        "April": 30,
        "May": 31,
        "June": 30,
        "July": 31,
        "August": 31,
        "September": 30,
        "October": 31,
        "November": 30,
        "December": 31}
    nameSet = set(monthDic)
    print(nameSet)
    print(set(monthDic.values()))

    # 加 减 in判断
    nameSet.add("Test")
    nameSet.add("Test")
    nameSet.add("Test")
    nameSet.add("Test")
    print("add Test 4 times:", nameSet)
    if "Test" in nameSet:
        nameSet.remove("Test")
    print("remove Test:     ", nameSet)

    # 遍历
    for name in nameSet:
        print("for-in ", name)

    set2 = {"January", "March", "May", "July", "August", "October", "December", "2023", 2023}
    print("set2", set2)
    print("set2 nameSet 并集", set2.union(nameSet))
    print("set2 nameSet 交集", set2.intersection(nameSet))
    print("set2-nameSet 差集", set2.difference(nameSet))
    print("nameSet-set2 差集", nameSet.difference(set2))
    print("set2 nameSet 对称差集(并集减去交集)", set2.symmetric_difference(nameSet))


if __name__ == '__main__':
    demo()